#!/bin/bash
echo "安装ufw防火墙、fail2ban"


# 更新包列表并安装ufw防火墙、
echo "更新包列表并安装ufw防火墙"
sudo apt update && sudo apt install -y ufw
echo "已成功配置ufw防火墙"

# 开启ufw并放行指定端口
sudo ufw allow 30703/tcp
sudo ufw allow 22/tcp
echo "已成功放行1panel 30703端口&ssh 22端口"
sudo ufw enable
echo "ufw防火墙已启动"


# 安装并启动fail2ban
echo "安装fail2ban---------"
sudo apt-get install -y fail2ban rsyslog
echo "启动 Fail2ban 服务"
sudo systemctl start fail2ban
echo "Fail2ban 开启开机自启动"
sudo systemctl enable fail2ban
echo "查看 Fail2ban 服务状态"
sudo systemctl status fail2ban


# 输出完成消息（可选）
echo "防火墙配置完成，fail2ban已安装并启动。"
echo "关于防火墙端口放行、Fail2ban参数及解禁黑名单ip等，请直接在1pannl面板上设"